package com.items.blog.mapper;

import com.items.blog.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    //根据用户名查询用户信息
    //查询有效信息 delete_flag默认等于0
    @Select("select * from user where user_name =#{userName} and delete_flag=0")
    UserInfo queryByName(String userName);

    //根据用户ID查询用户信息
    @Select("select * from user where id = #{id} and delete_flag=0")
    UserInfo queryById(Integer id);

    //保存注册数据
    @Insert("INSERT INTO user(user_name, password, email,salt,confirm_code,activation_time,is_valid) " +
            "VALUES(#{userName}, #{password},#{email},#{salt},#{confirmCode},#{activationTime},#{isValid})")
    int insertUser(UserInfo userInfo);

    //根据确认码查询用户
    @Select("select email,activation_time from user where confirm_code = #{confirmCode} and is_valid = 0")
    UserInfo selectUserByConfirmCode( @Param("confirmCode") String confirmCode);
    //根据确认码查询用户并修改确认值为1
    @Update("update user set is_valid = 1 where confirm_code=#{confirmCode}")
    int updateUserByConfirmCode(@Param("confirmCode") String confirmCode);

    //根据邮箱去查询账号
    @Select("select email,password,salt from user where eamil = #{email} and is_valid =1")
    List<UserInfo> selectUserByEmail(@Param("email") String email);
}
